// Copyright © SixtyFPS GmbH <info@slint.dev>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0

Test := Rectangle {
    property<color> b1: blue;
    property<color> b2: #00f;
    property<color> b3: #0000ff;
    property<color> b4: #00ff;
    property<color> b5: #0000ffff;
    property<color> r1: red;
    property<color> r2: #f00;
    property<color> r3: #ff0000;
    property<color> r4: #f00f;
    property<color> r5: #ff0000ff;

    property<color> y1: yellow;
    property<color> y2: #ff0;

    property<color> g1: #999;

    property<color> c1: #ff335588;
    property<color> c2: rgb(100, 23, 42);
    property<color> c3: rgba(39%, 50%, 16%, 81%);

    property<color> i1: rgb(0, 666, -85);

    // allow to use `mix` on colors
    property<color> p1: true ? b1.mix(r1, 30%) : y1.mix(c1, 70%);
    // allow to use `with_alpha` on colors
    property<brush> invisible: b1.with-alpha(0%);

    property<float> b1hue: 240.0;
    property<float> b1sat: 1.0;
    property<float> b1bri: 1.0;

    property<float> r1hue: 0.0;
    property<float> r1sat: 1.0;
    property<float> r1bri: 1.0;

    property<float> y1hue: 60.0;
    property<float> y1sat: 1.0;
    property<float> y1bri: 1.0;

    property <color> gr1: green;
    property<float> gr1hue: 120.0;
    property<float> gr1sat: 1.0;
    property<float> gr1bri: 0.501960813999176;
    property <color> new_green: hsv(120.0, 1.0, 0.501960813999176);

    // burlywood
    property<color> bwood: Colors.burlywood;
    property<float> bwood_hue: 33.79310607910156;
    property<float> bwood_sat: 0.39189186692237854;
    property<float> bwood_bri: 0.8705882430076599;

    out property <bool> test_rgb: Colors.blue.blue == 255 && Colors.blue.red == 0 && Colors.blue.green == 0 && Colors.blue.alpha == 255
        && Colors.rgb(45, 12, 78).red == 45 && Colors.rgb(45, 12, 78).green == 12 && Colors.rgba(45, 12, 78, 12/255).alpha == 12 && Colors.rgba(145, 112, 178, 85%).alpha == floor(85% * 255)
        && #abc.green == (11 * 16 + 11) && #abcd.alpha == (13 * 16 + 13) && #abcdef.red == (10 * 16 + 11);

    out property <bool> test_hsv: gr1.to-hsv().hue == new_green.to-hsv().hue && gr1.to-hsv().saturation == new_green.to-hsv().saturation && gr1.to-hsv().value == new_green.to-hsv().value
        && bwood == Colors.hsv(bwood_hue, bwood_sat, bwood_bri);
    out property <bool> test_hsv_wrap: Colors.blue == hsv(240, 1, 1) && Colors.blue == hsv(600, 1, 1) && Colors.blue == hsv(-120, 1, 1);
    out property <bool> test_hsv_hue: b1.to-hsv().hue == b1hue && r1.to-hsv().hue == r1hue && y1.to-hsv().hue == y1hue && gr1.to-hsv().hue == gr1hue && bwood.to-hsv().hue == bwood_hue;
    out property <bool> test_hsv_sat: b1.to-hsv().saturation == b1sat && r1.to-hsv().saturation == r1sat && y1.to-hsv().saturation == y1sat && gr1.to-hsv().saturation == gr1sat && bwood.to-hsv().saturation == bwood_sat;
    out property <bool> test_hsv_bri: b1.to-hsv().value == b1bri && r1.to-hsv().value == r1bri && y1.to-hsv().value == y1bri && gr1.to-hsv().value == gr1bri && bwood.to-hsv().value == bwood_bri;

    property<bool> test: b1 == b2 && b2 == b5 && b3 == Colors.blue && Colors.red == r4 && y1 == Colors.rgba(255, 100%, 0, 100%)
        && test_rgb && test_hsv && test_hsv_hue && test_hsv_sat && test_hsv_bri && test_hsv_wrap;
}

/*
```cpp
auto handle = Test::create();
const Test &t = *handle;
assert_eq(t.get_r1(), t.get_r2());
assert_eq(t.get_r1(), t.get_r3());
assert_eq(t.get_r1(), t.get_r4());
assert_eq(t.get_r1(), t.get_r5());
assert_eq(t.get_b1(), t.get_b2());
assert_eq(t.get_b1(), t.get_b3());
assert_eq(t.get_b1(), t.get_b4());
assert_eq(t.get_b1(), t.get_b5());
assert(t.get_b1() != t.get_r5());
assert_eq(t.get_y1(), t.get_y2());

auto red = slint::Color::from_argb_float(1, 1, 0, 0);
auto blue = slint::Color::from_rgb_float(0, 0, 1);
auto g = slint::Color::from_rgb_uint8(0x99, 0x99, 0x99);
assert_eq(t.get_r1(), red);
assert_eq(t.get_b1(), blue);
assert_eq(t.get_g1(), g);
assert_eq(t.get_y1(), slint::Color::from_argb_encoded(0xffffff00));

t.set_g1(blue);
assert_eq(t.get_g1(), t.get_b1());

assert_eq(t.get_c1().alpha(), 0x88);
assert_eq(t.get_c1().red(), 0xff);
assert_eq(t.get_c1().green(), 0x33);
assert_eq(t.get_c1().blue(), 0x55);

assert_eq(t.get_c2().alpha(), 0xff);
assert_eq(t.get_c2().red(), 100);
assert_eq(t.get_c2().green(), 23);
assert_eq(t.get_c2().blue(), 42);

assert_eq(t.get_c3().alpha(), uint8_t(255.*0.81));
assert_eq(t.get_c3().red(), uint8_t(255.*0.39));
assert_eq(t.get_c3().green(), uint8_t(255.*0.50));
assert_eq(t.get_c3().blue(), uint8_t(255.*0.16));

assert_eq(t.get_i1().alpha(), 0xff);
assert_eq(t.get_i1().red(), 0);
assert_eq(t.get_i1().green(), 255);
assert_eq(t.get_i1().blue(), 0);

assert(t.get_test_rgb());
assert(t.get_test());
```


```rust
let t = Test::new().unwrap();
assert_eq!(t.get_r1(), t.get_r2());
assert_eq!(t.get_r1(), t.get_r3());
assert_eq!(t.get_r1(), t.get_r4());
assert_eq!(t.get_r1(), t.get_r5());
assert_eq!(t.get_b1(), t.get_b2());
assert_eq!(t.get_b1(), t.get_b3());
assert_eq!(t.get_b1(), t.get_b4());
assert_eq!(t.get_b1(), t.get_b5());
assert_ne!(t.get_b1(), t.get_r5());
assert_eq!(t.get_y1(), t.get_y2());

let red = slint::Color::from_argb_f32(1., 1., 0., 0.);
let blue = slint::Color::from_rgb_f32(0., 0., 1.);
let g = slint::Color::from_rgb_u8(0x99, 0x99, 0x99);
assert_eq!(t.get_r1(), red);
assert_eq!(t.get_b1(), blue);
assert_eq!(t.get_g1(), g);
assert_eq!(t.get_y1(), slint::Color::from_argb_encoded(0xffffff00));

t.set_g1(blue);
assert_eq!(t.get_g1(), t.get_b1());

assert_eq!(t.get_c1().alpha(), 0x88);
assert_eq!(t.get_c1().red(), 0xff);
assert_eq!(t.get_c1().green(), 0x33);
assert_eq!(t.get_c1().blue(), 0x55);

assert_eq!(t.get_c2().alpha(), 0xff);
assert_eq!(t.get_c2().red(), 100);
assert_eq!(t.get_c2().green(), 23);
assert_eq!(t.get_c2().blue(), 42);

assert_eq!(t.get_c3().alpha(), (255.*0.81) as u8);
assert_eq!(t.get_c3().red(), (255.*0.39) as u8);
assert_eq!(t.get_c3().green(), (255.*0.50) as u8);
assert_eq!(t.get_c3().blue(), (255.*0.16) as u8);

assert_eq!(t.get_i1().alpha(), 0xff);
assert_eq!(t.get_i1().red(), 0);
assert_eq!(t.get_i1().green(), 255);
assert_eq!(t.get_i1().blue(), 0);

assert!(t.get_test_rgb());
assert!(t.get_test());

```

```js
var t = new slint.Test({});
assert(t.r1.toString() == t.r2.toString());
assert(t.r1.toString() == t.r3.toString());
assert(t.r1.toString() == t.r4.toString());
assert(t.r1.toString() == t.r5.toString());
assert(t.b1.toString() == t.b2.toString());
assert(t.b1.toString() == t.b3.toString());
assert(t.b1.toString() == t.b4.toString());
assert(t.b1.toString() == t.b5.toString());
assert(t.b1.toString() != t.r5.toString());

let red = "#ff0000ff";
let blue = "#0000ffff";
let g = "#999999ff";
assert.equal(t.r1.toString(), red);
assert.equal(t.b1.toString(), blue);
assert.equal(t.g1.toString(), g);
assert.equal(t.y1.toString(), "#ffff00ff");

t.g1 = "blue";
assert.equal(t.g1.toString(), t.b1.toString());
t.g1 = "#f00";
assert.equal(t.g1.toString(), t.r1.toString());

assert.equal(t.c1.toString(), "#ff335588");
assert.equal(t.c2.toString(), "#64172aff");
assert.equal(t.c3.toString(), "#637f28ce");
assert.equal(t.i1.toString(), "#00ff00ff");

assert(t.test_rgb);
assert(t.test);

```
*/
